<?php


namespace app\api\controller\v1;


use app\api\controller\BaseController;
use app\api\service\RedisKeyValidate;
use think\Exception;

class Redis extends BaseController
{
    private $redis_object;

    public function __construct()
    {
        $bool = config('app.app_debug');
        if($bool == false){
            return;
        }
        $this->redis_object = new \app\common\controller\Redis();
    }

    /**获取所有的key
     * @return \think\response\Json
     */
    public function all()
    {
        return $this->redis_object->allKeys();
    }

    /**
     * 通过key获取对应的值string
     * @param $key redis_string_key
     * @return bool|string
     * @throws \app\lib\exception\ParameterException
     */
    public function string($key)
    {
        (new RedisKeyValidate()) ->goCheck();
        return $this->redis_object->get_string($key);
    }

    /**
     * 通过key获取整个hash的值
     * @param $key redis_hash_key
     * @return \think\response\Json
     * @throws \app\lib\exception\ParameterException
     */
    public function hash($key)
    {
        (new RedisKeyValidate()) ->goCheck();
        return $this->redis_object->get_hash($key);
    }

    /**
     * 通过key获取整个set的元素
     * @param $key
     * @return \think\response\Json
     * @throws \app\lib\exception\ParameterException
     */
    public function set($key)
    {
        (new RedisKeyValidate()) ->goCheck();
        return $this->redis_object->get_set($key);
    }

    public function del($key)
    {
        (new RedisKeyValidate()) ->goCheck();
        return $this->redis_object->del_key($key);
    }

    public function lists($key)
    {
        (new RedisKeyValidate()) ->goCheck();
        return $this->redis_object->get_list($key);
    }
}